#ifndef Project00_H
#define Project00_H

#include "SmallEngine.h"
#include "Sandbox.h"
// #include "ScriptCommon.h"

#include "ProjectBlur.h"
#include "ProjectArtColor.h"
#include "ProjectHeartfelt.h"
#include "ProjectWaterWave.h"

class Project00 : public Sandbox
{
public:
    Project00(const std::string &name = "Sandbox", CC::Scene* scene = nullptr);
	virtual ~Project00();

	virtual void OnAttach() override;
	virtual void OnDetach() override;

    virtual void OnUpdate(CC::Timestep ts, std::string renderscene = "") override;

    virtual void OnKeyWinPressed(CC::KeyWinEvent &e) override;
    

private:
	glm::vec4 m_ClearColor = {0.0f, 0.0f, 0.0f, 1.0f};

private:

    template <typename T>
    void HandleDeleteLastLayer(std::string title, int newPage, std::function<void()> callback) {

        //CC_INFO("HandleDeleteLastLayer m_newPage=%d", newPage);

        if (0 == newPage) return;
        if (m_currentPage == newPage) {
            callback();
            return;
        }

        if (0 == m_currentPage) {

        }
        else {
            int p = m_currentPage;
            m_currentPage = 0;
            CC::Application::Get().SubmitToMainThread(CC::ThreadInfo([=](void* param) {
                CC::Application::Get().PopLayer(m_widgets[p-1]);
                delete m_widgets[p - 1];
                m_widgets[p - 1] = nullptr;

                }, nullptr));
        }

        CC::Scene* s = new CC::Scene();
        s->LoadFont(PATHCONFIG("assets/fonts/Alimama_DongFangDaKai_Regular.ttf"), "Alimama_DongFangDaKai_Regular");

        CC::Application::Get().SubmitToMainThread(CC::ThreadInfo([=](void* param) {
            m_widgets[newPage - 1] = new T(title, (CC::Scene*)(param));
            CC::Application::Get().PushLayer(m_widgets[newPage-1]);
            
            m_currentPage = newPage;
            callback();
            }, s));
        
    }

    int m_currentPage;

    ProjectSandbox* m_widgets[4];

};

#endif